package com.atguigu.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.awt.font.TextAttribute;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * ClassName: ConnectionTest
 * Package: com.atguigu.hbase
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/3/26 15:12
 * @Version: 1.0
 */
public class ConnectionTest {
    public static void testConnection() throws IOException, ExecutionException, InterruptedException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum", "localhost:12181");
//        conf.set("hbase.zookeeper.quorum" , "hadoop102,hadoop103,hadoop104");

        // 同步连接
//        Connection connection = ConnectionFactory.createConnection(conf);
//        System.out.println("同步连接：" + connection);
//        connection.close();


        // 异步连接
        CompletableFuture<AsyncConnection> asyncConnection =
                ConnectionFactory.createAsyncConnection(conf);
        System.out.println("异步连接：" + asyncConnection.get());
        asyncConnection.get().close();
    }

    public static void main(String[] args) throws Exception {
        testConnection();
    }
}
